﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Linq
Imports System.Web
Imports sonicERPDAL
Imports sonicERPinfo
Imports Newtonsoft.Json
Imports System.Web.Script.Services
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="sonicERPinterface")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WSdal
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function getcliente(ByVal _criterio As String) As String
        Dim dal As New ClienteDAL
        Dim info As New Tabelainfo
        info.cliente.nomecliente = _criterio
        Dim dv As DataView = dal.Getlista(info)

        Dim lista As List(Of String) = New List(Of String)

        For Each item As DataRow In dv.Table.Rows
            lista.Add(item(0).ToString())
        Next

        Return JsonConvert.SerializeObject(lista, Formatting.Indented)

    End Function

    <WebMethod()> _
    Public Function getfornecedor(ByVal _criterio As String) As String
        Dim dal As New fornecedorDAL
        Dim info As New Tabelainfo
        info.fornecedor.nomefornecedor = _criterio
        Dim dv As DataView = dal.pesquisanomefornecedor(info)

        Dim lista As List(Of String) = New List(Of String)

        For Each item As DataRow In dv.Table.Rows
            lista.Add(item(0).ToString())
        Next

        Return JsonConvert.SerializeObject(lista, Formatting.Indented)

    End Function

    <WebMethod()> _
    Public Function getusuario(ByVal _criterio As String) As String
        Dim dal As New UsuarioDAL
        Dim info As New Tabelainfo
        info.usuario.apelido = _criterio
        Dim dv As DataView = dal.pesquisanomeusuario(info)

        Dim lista As List(Of String) = New List(Of String)

        For Each item As DataRow In dv.Table.Rows
            lista.Add(item(0).ToString())
        Next

        Return JsonConvert.SerializeObject(lista, Formatting.Indented)

    End Function


    <WebMethod()> _
    Public Function getnivelusuario(ByVal _criterio As String) As String
        Dim dal As New nivelUsuarioDAL
        Dim info As New Tabelainfo
        info.nivelusuario.nivel = _criterio
        Dim dv As DataView = dal.pesquisanomenivelusuario(info)
        Dim lista As List(Of String) = New List(Of String)

        For Each item As DataRow In dv.Table.Rows
            lista.Add(item(0).ToString())
        Next

        Return JsonConvert.SerializeObject(lista, Formatting.Indented)

    End Function

End Class